package com.frxuexi.mdm2202.ui.demo

import android.util.Log
import android.util.Size
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountCircle
import androidx.compose.material.icons.filled.Lock
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.frxuexi.mdm2202.R


@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    var myname by remember {
        mutableStateOf("")
    }
    //Column：垂直布局,Row:水平布局
    Column {
        Text(
            text = "Hello $name!",
            modifier = modifier,
            color = Color.Blue,
            fontSize = 22.sp,
            fontWeight = FontWeight.Bold,
            lineHeight = 50.sp
        )
        Text(text = "hello")
        TextField(value = myname, onValueChange = {
            myname = it
        },
            label = { Text(text = "用户名") },
            leadingIcon = {
                Icon(
                    imageVector = Icons.Default.AccountCircle,
                    contentDescription = ""
                )
            },
            trailingIcon = { Text(text = "验证码") })
    }

}

@Composable
fun MyCom() {
    var mypass by remember {
        mutableStateOf("")
    }
    /*Column(content={
        Text(text = "Hello", modifier = Modifier
            .fillMaxWidth()
//            .padding(20.dp)
//            .padding(horizontal = 20.dp, vertical = 10.dp)
//            .padding(start = 10.dp)
//            .padding(paddingValues = PaddingValues(20.dp))
            .background(Color.Gray))
//        Spacer(modifier = Modifier.height(10.dp))
        Text(text = "Hello")
        OutlinedTextField(value = mypass, onValueChange = {mypass=it},
            leadingIcon = {
                Icon(
                    imageVector = Icons.Default.Lock,
                    contentDescription = ""
                )
            },
            visualTransformation= PasswordVisualTransformation(),
            shape = RoundedCornerShape(50)
        )
    })*/
    Column(
        Modifier.fillMaxHeight(),//高度填满
        verticalArrangement = Arrangement.spacedBy(10.dp),//垂直方向子控件之间间距
//        verticalArrangement = Arrangement.SpaceEvenly,//垂直方向的对齐方式
        horizontalAlignment = Alignment.CenterHorizontally//垂直方向的对齐方式
    ) {
//        Spacer(modifier = Modifier.height(10.dp))
        Text(
            text = "Hello", modifier = Modifier
                .fillMaxWidth()
//            .padding(20.dp)
//            .padding(horizontal = 20.dp, vertical = 10.dp)
//            .padding(start = 10.dp)
//            .padding(paddingValues = PaddingValues(20.dp))
                .background(Color.Gray)
        )
//        Spacer(modifier = Modifier.height(10.dp))
        Text(text = "Hello")
        Text(text = "Hello")
        OutlinedTextField(
            value = mypass, onValueChange = { mypass = it },
            leadingIcon = {
                Icon(
                    imageVector = Icons.Default.Lock,
                    contentDescription = ""
                )
            },//左侧图标
            /*trailingIcon = {
                Icon(
                    painter = painterResource(id = R.drawable.ic_launcher_background),
                    contentDescription = ""
                )
            },*/
            visualTransformation = PasswordVisualTransformation(),//密文形式
            shape = RoundedCornerShape(50)//圆角
        )
        Button(
            onClick = {//点击事件
                Log.i("===", "提交执行了")
            },
            colors = ButtonDefaults.buttonColors(
                contentColor = Color.Yellow,//按钮文字颜色
                containerColor = Color.Gray//按钮背景颜色
            )
        ) {
            Text(text = "提交")
        }
        FilledTonalButton(onClick = { }) {
            Text(text = "提交")
        }
        OutlinedButton(onClick = { /*TODO*/ }) {
            Text(text = "提交")
        }
        TextButton(
            onClick = { }
        ) {
            Text("Text Button")
        }

        Text(text = "文本", modifier = Modifier.clickable {//所有组件的点击实现
            Log.i("===", "文本点击了")
        })
    }
}
